//
//  ARCate5Cell.m
//  AriseSamePro
//
//  Created by 包日守 on 15/10/24.
//  Copyright © 2015年 Arise. All rights reserved.
//

#import "ARCate5Cell.h"

#import "Masonry.h"

@interface ARCate5Cell()

@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageV;


@property (weak, nonatomic) IBOutlet UILabel *channelTitleLabel;
@property (weak, nonatomic) IBOutlet UIImageView *channelImageV;


@property (weak, nonatomic) IBOutlet UILabel *contentLabel;


@property (weak, nonatomic) IBOutlet UILabel *likeCountLabel;
@property (weak, nonatomic) IBOutlet UILabel *viewsCountLabel;

@property (weak, nonatomic) IBOutlet UIButton *likeButton;





@end

@implementation ARCate5Cell

- (IBAction)channelButtonClick:(id)sender {
    
    if (self.ChannelButtonClick) {
        self.ChannelButtonClick(self.cateModel);
    }
    
}



- (UIButton *) myLikeButton
{

    return self.likeButton;
}

- (ARLikeAnimation *)likeAnimation
{
    if (_likeAnimation == nil) {
        
        _likeAnimation =
         [[ARLikeAnimation alloc] initWithFrame:CGRectZero];
        
        
    }
    return _likeAnimation;

}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setCateModel:(ARCate5Model *)cateModel
{
    _cateModel = cateModel;
    self.iconImageV.image = nil;
    self.channelImageV.image = nil;
    
    [self.iconImageV setImageWithURL:[NSURL URLWithString:cateModel.userModel.avatar]];
    self.titleLabel.text = cateModel.userModel.username;
    
    [self.channelImageV setImageWithURL:[NSURL URLWithString:cateModel.mediaModel.channelModel.icon]];
    
    ARChannelModel *data = cateModel.mediaModel.channelModel;
    
    self.channelTitleLabel.text = data.name;
    
    self.contentLabel.text = cateModel.txt;
    
    self.likeCountLabel.text = [cateModel.likes stringValue];
    self.viewsCountLabel.text = [cateModel.views stringValue];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    [self refreshLikeButton];
    
    

}

- (IBAction)shareClick:(id)sender {
    if (self.ShareBtnBlock) {
        self.ShareBtnBlock(self.cateModel,sender);
    }
    
    
}

- (IBAction)talkClick:(id)sender {
}


- (IBAction)likeClick:(id)sender {
    [self likeButtonAction];
}
- (void) likeButtonAction
{
    self.cateModel.is_liked = !self.cateModel.is_liked;
    if (self.cateModel.is_liked == YES) {
        
        
        [[self myLikeButton] addSubview:self.likeAnimation];
        
        [self performSelector:@selector(refreshLikeButton) withObject:nil afterDelay:0.4];
        
        
    }
    else
    {
        [self refreshLikeButton];
    }
    

}


- (void)refreshLikeButton
{
    [self.likeAnimation removeFromSuperview];
    
    UIImage *image =!self.cateModel.is_liked?[UIImage imageNamed:@"love@2x"]:[UIImage imageNamed:@"love_selected@2x"];
    [ [self myLikeButton] setImage:image forState:UIControlStateNormal];
}
- (IBAction)channelClick:(id)sender {
}
- (IBAction)packClick:(id)sender {
}




@end
